﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO.Bussiness.Repository;
using DAO.Model;

namespace new_Seminario.ABM
{
    public partial class Roles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAceptaComandar_Click(object sender, EventArgs e)
        {
            RolRepository rr = new RolRepository();
            Rol rol = new Rol();

            try
            {
                rol.Descripcion = txbRol.Text.Trim();
                System.Web.Security.Roles.CreateRole(txbRol.Text.Trim());
            }
            catch
            {
            }
            finally
            {
                rr.Add(rol);
                rr.Save();
                CleanControl(this.Controls);
                Response.Redirect("roles.aspx");
            }
        }

        protected void btnCancelarComanda_Click(object sender, EventArgs e)
        {
            Response.Redirect("home.aspx");
        }
        public void CleanControl(ControlCollection controles)
        {
            foreach (Control control in controles)
            {
                if (control is TextBox)
                    ((TextBox)control).Text = string.Empty;
                else if (control.HasControls())
                    //Esta linea detécta un Control que contenga otros Controles
                    //Así ningún control se quedará sin ser limpiado.
                    CleanControl(control.Controls);
            }
        }

        protected void gvRoles_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            /*System.Web.Security.Roles.DeleteRole(gvRoles.Rows[((System.Web.UI.WebControls.GridView)(sender)).PageIndex].Cells[2].Text);*/
        }

        protected void gvRoles_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            /*System.Web.Security.Roles.DeleteRole(gvRoles.Rows[((System.Web.UI.WebControls.GridView)(sender)).CellPadding + 1].Cells[2].Text);*/
        }

        protected void gvRoles_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {

        }
    }
}